package org.cid54.jshopper.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.cid54.jshopper.dao.UserGroupDao;
import org.cid54.jshopper.model.User;
import org.cid54.jshopper.model.UserGroup;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 *
 * @author fgo
 */
@Repository
public class UserGroupDaoImpl extends SuperEntityDaoImpl<UserGroup> implements UserGroupDao {

    @Override
    protected Class getEntityClass() {
        return UserGroup.class;
    }

    @Override
    public UserGroup findByName(String name) {
        Criteria criteria = this.getNewCriteria();

        criteria.add(Restrictions.eq("name", name));

        return (UserGroup) criteria.uniqueResult();
    }

    @Override
    public List<UserGroup> findByUser(User u) {

        return new ArrayList<UserGroup>(u.getUserGroups());

    }

    @Override
    protected boolean isSortableByName() {
        return true;
    }
}
